Match a word containing ‘z’¶
pattern = ‘w*z.w*’
Write a python program that matches a word containing ‘z’.
import re
def text_match(S):
pattern = '\w*z.\w*'
if re.search(pattern, S):
return 'Found a match!'
else:
return('Not matched!')
# test
print(text_match("The quick brown fox jumps over the lazy dog."))
print(text_match("Python Exercises."))
Output:
Found a match!
Not matched!